package cn.tedu.zuoye.controller;

import cn.tedu.zuoye.dao.UserMapper;
import cn.tedu.zuoye.pojo.param.UserParam;
import cn.tedu.zuoye.pojo.po.User;
import cn.tedu.zuoye.pojo.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@Api(value = "user",tags = "用户")
@Slf4j
@Validated
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    UserMapper userMapper;

    @ApiOperation("用户详情")
    @PostMapping("/userById")
    public UserVO selectUserById(Long id){
        UserVO userVO = new UserVO();
        log.info("开始根据id查询");
        User user = userMapper.selectByPrimaryKey(id);
        BeanUtils.copyProperties(user,userVO);
        log.info("查询到的数据为：{}",user);
        return userVO;
    }

    @ApiOperation("用户列表")
    @PostMapping("/detail")
    public List<UserVO> selectUser(){

        List<UserVO> userList ;
        log.info("开始处理查询用户列表");
        userList = userMapper.selectUser();
        for (UserVO user : userList){
            log.info("查询到的数据为：{}",user);
        }
        return userList;
    }
}
